package java_excel;

import jxl.*;
import jxl.read.biff.BiffException;

import java.io.File;
import java.io.IOException;

public class JavaExcelReadDataTypes {
    public static void main(String[] args) {
        Workbook wrk1;
        try {
            wrk1 = Workbook.getWorkbook(new File("Test.xls"));

            //Obtain the reference to the first sheet in the workbook
            Sheet sheet1 = wrk1.getSheet(0);

            //Obtain reference to the Cell using getCell(int col,int row)
            Cell cell1 = sheet1.getCell(0, 0);
            Cell cell2 = sheet1.getCell(1, 0);
            Cell cell3 = sheet1.getCell(2, 0);
            Cell cell4 = sheet1.getCell(3, 0);

            DateCell dateCell = null;
            NumberCell numberCell = null;
            BooleanCell booleanCell = null;
            LabelCell labelCell = null;

            //<span id="IL_AD9" class="IL_AD">Check</span> the Type of the Cell contents and assign the object to the appropriate reference type
            if (cell1.getType() == CellType.DATE) {
                dateCell = (DateCell) cell1;
            }

            if (cell2.getType() == CellType.NUMBER) {
                numberCell = (NumberCell) cell2;
            }

            if (cell3.getType() == CellType.BOOLEAN) {
                booleanCell = (BooleanCell) cell3;
            }

            if (cell4.getType() == CellType.LABEL) {
                labelCell = (LabelCell) cell4;
            }

            System.out.println("Value of Date Cell is: " + dateCell.getDate());
            System.out.println("Value of Number Cell is: " + numberCell.getValue());
            System.out.println("Value of Boolean Cell is: " + booleanCell.getValue());
            System.out.println("Value of Label Cell is: " + labelCell.getString());
        }catch (BiffException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
